package com.nekonomics
package utils

import sourcecode.{Enclosing, Name, File, Line}
import zio.{Task, ZIO}

def traced[A](label: String)(zio: Task[A]): Task[A] =
  zio
    .tapError(e => ZIO.logError(s"[$label] failed: $e"))
//    .mapError(e => new RuntimeException(s"[$label] error", e))
  
def traced[A](res: Task[A])(using enclosing: Enclosing, file: File, line: Line): Task[A] =
  res.tapError { e =>
    ZIO.logError(s"【${file.value}:${line.value}】 @ ${enclosing.value} failed: $e")
  }